
package com.joysuch.wwyt.bp.enums;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum SafetyWorkTypes {

    DIAO_ZHUANG(1, "吊装", "diaozhuang"),
    SHOU_XIAN_KONG_JIAN(2, "受限空间", "shouxiankongjian"),
    GAO_CHU(3, "高处", "gaochu"),
    LIN_SHI_YONG_DIAN(4, "临时用电", "linshiyongdian"),
    MANG_BAN_CHOU_DU(5, "盲板抽堵", "mangbanchoudu"),
    DONG_TU(6, "动土", "dongtu"),
    DUAN_LU(7, "断路", "duanlu"),
    DONG_HUO(8, "动火", "donghuo"),
    YI_BAN(9, "一般", "yiban");

    private int id;
    private String code;
    private String name;

    private SafetyWorkTypes(int id, String name, String code) {
        this.id = id;
        this.name = name;
        this.code = code;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public static SafetyWorkTypes findByName(String name) {
        SafetyWorkTypes[] values = SafetyWorkTypes.values();
        for (SafetyWorkTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static SafetyWorkTypes findByCode(String code) {
        SafetyWorkTypes[] values = SafetyWorkTypes.values();
        for (SafetyWorkTypes v : values) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

    public static SafetyWorkTypes findById(Integer level) {
        SafetyWorkTypes[] values = SafetyWorkTypes.values();
        for (SafetyWorkTypes v : values) {
            if (v.getId() == level) {
                return v;
            }
        }
        return null;
    }

    public static String findNameById(Integer level) {
        SafetyWorkTypes[] values = SafetyWorkTypes.values();
        for (SafetyWorkTypes v : values) {
            if (v.getId() == level) {
                return v.getName();
            }
        }
        return null;
    }

    public static List<String> getAllName(){
        SafetyWorkTypes[] values = SafetyWorkTypes.values();
        return Arrays.asList(values).stream().map(r -> r.getName()).collect(Collectors.toList());
    }
}
